package com.netty.fastthread;

import java.util.Random;

/**
 * @author xl-9527
 * @since 2024/6/17
 **/
public class FastThreadLocalDemo {

    private static final Random RANDOM = new Random();
    private static final Integer CAPACITY = -1 >>> Integer.numberOfLeadingZeros(46);

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            m1();
            m2();
        }
    }

    public static void m1() {
        final long start = System.nanoTime();
        final int CAPACITY_NEW = CAPACITY + 1;
        for (int i = 0; i < 100000; i++) {
            final int a = RANDOM.nextInt();
            int aa = a % CAPACITY_NEW;
        }
        System.out.println("m1 运行的时间：" + (System.nanoTime() - start));
    }


    public static void m2() {
        final long start = System.nanoTime();
        for (int i = 0; i < 100000; i++) {
            final int a = RANDOM.nextInt();
            int aa = a & CAPACITY;
        }
        System.out.println("m2 运行的时间：" + (System.nanoTime() - start));
    }
}
